// 字典树
//  https://www.luogu.com.cn/problem/T178443?contestId=59541
#include <iostream>
using namespace std;
#define MAX_SIZE 100005

int n, cnt = 0;
int trie[MAX_SIZE][26];
int sum[MAX_SIZE];  // 第i个节点的子树个数
// int cnt[MAX_SIZE];
string name[MAX_SIZE];

void add(string x) {
    int siz = x.size();
    int p = 0;
    for (int i = 0; i < siz; i++) {
        if (trie[p][x[i] - 'a'] == 0)
            trie[p][x[i] - 'a'] = ++cnt;

        sum[p]++;
        p = trie[p][x[i] - 'a'];
    }
    sum[p]++;
}

int find(string x)  // 前缀为 x 的字符串个数
{
    int p = 0, siz = x.size();
    for (int i = 0; i < siz; i++)
        p = trie[p][x[i] - 'a'];
    return sum[p];
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> name[i];
        add(name[i]);
    }
    for (int i = 1; i <= n; ++i)
        cout << find(name[i]) - 1 << endl;
}
